
package guipk;

import commonpk.DBOperation;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
import java.io.File;
import java.sql.SQLException;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import substancepk.Country;

/**
 *
 * @author LJC
 */
public class FlagFrame extends javax.swing.JFrame {

    //*****************************************************************************
    /* 成员 */
    private ImageIcon                  chinaImage;                  // 中国国旗
    private ImageIcon                  flagImage;                   // 国旗图片
    private DefaultListModel           defaultListModel;            // Model
    private Country                    tempCountry;                 // 当前国家
    private final DBOperation          DBO = new DBOperation();     // 数据库类
    private JFileChooser               fc;                          // 文件选择器
    
    /* 属性 */
    private String                     countryName;                 // 国家全名
    private String                     countryChineseBrief;         // 中文简称
    private String                     countryEnglishBrief;         // 英文简称
    private String                     countryId;                   // 国家序号
    private String                     countryType;                 // 国家种类
    private String                     countryBirth;                // 建国时间
    private String                     countryInfo;                 // 国家简介
    private String                     countryFlagPath;             // 存储路径
    private String                     chinaFlagPath;               // 中国国旗路径
    private String                     flagPath;                    // 国旗路径
    //*****************************************************************************
    
    
    
    //**********************************************************************
    /* 构造器 */
    
    public FlagFrame() {
        // 配置窗口
        initComponents();
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        // 配置属性
        this.chinaFlagPath = "F:\\图片\\flag\\zhongguo.png";  
        //构造成员
        this.defaultListModel = new DefaultListModel<>();
        this.resultList.setModel(defaultListModel);
        this.fc = new JFileChooser();
        this.fc.setCurrentDirectory(new File("D:\\"));
        chinaImage = new ImageIcon(chinaFlagPath);
    }
    //**********************************************************************
    
    
    //**********************************************************************
    /* Pickers */
    
    public void pickAll(){
        pickCountryName();
        pickCountryChineseBrief();
        pickCountryEnglishBrief();
        pickCountryId();
        pickCountryType();
        pickCountryBirth();
        pickCountryInfo();
        pickCountryFlagPath();
    }
    
    public void pickCountryName(){
        this.countryName = this.CountryNameTextField.getText();
    }
    
    public void pickCountryChineseBrief(){
        this.countryChineseBrief = this.CountryChineseBriefTextField.getText();
    }
    
    public void pickCountryEnglishBrief(){
        this.countryEnglishBrief = this.CountryEnglishBriefTextField.getText();
    }
    
    public void pickCountryId(){
        this.countryId = this.CountryIdTextField.getText();
    }
    
    public void pickCountryType(){
        this.countryType = this.countryTypeComboBox.getSelectedItem().toString();
    }
    
    public void pickCountryBirth(){
        this.countryBirth = this.CountryBirthTextField.getText();
    }
    
    public void pickCountryInfo(){
        this.countryInfo = this.CountryInfoTextArea.getText();
    }
            
    public void pickCountryFlagPath(){
        this.countryFlagPath = this.pathTextField.getText();
    }
    
    //**********************************************************************
    
    
    
    //**********************************************************************
    /* 其他方法 */
    
    // 生成国家对象
    public Country getCountryInstance(){
        
        Country countryInstance;
        
        // 提取文本框数据
        pickAll();
        
        // 用提取结果 构造当前国家对象
        countryInstance = new Country();
        countryInstance.setCountryName(countryName);
        countryInstance.setCountryChineseBrief(countryChineseBrief);
        countryInstance.setCountryEnglishBrief(countryEnglishBrief);
        countryInstance.setCountryType(countryType);
        countryInstance.setCountryId(countryId);
        countryInstance.setCountryBirth(countryBirth);
        countryInstance.setCountryInfo(countryInfo);
        countryInstance.setCountryFlagPath(countryFlagPath);
        return countryInstance;
    }
    
    
    //显示当前对象
    public void showInstance(){
        this.CountryNameTextField.setText(this.tempCountry.getCountryName());
        this.CountryChineseBriefTextField.setText(this.tempCountry.getCountryChineseBrief());
        this.CountryEnglishBriefTextField.setText(this.tempCountry.getCountryEnglishBrief());
        this.CountryIdTextField.setText(this.tempCountry.getCountryId());
        this.countryTypeComboBox.setSelectedItem(this.tempCountry.getCountryType());
        this.CountryBirthTextField.setText(this.tempCountry.getCountryBirth());
        this.pathTextField.setText(this.tempCountry.getCountryFlagPath());
        this.CountryInfoTextArea.setText(this.tempCountry.getCountryInfo());
    }
    
    
    // 清空全部组件
    public void clearAll(){
        this.CountryNameTextField.setText("");
        this.CountryChineseBriefTextField.setText("");
        this.CountryEnglishBriefTextField.setText("");
        this.CountryIdTextField.setText("");
        this.CountryBirthTextField.setText("");
        this.countryTypeComboBox.setSelectedItem("发达国家");
        this.CountryInfoTextArea.setText("");
        this.pathTextField.setText("");
        this.FlagLabel.setIcon(chinaImage);
        this.defaultListModel.removeAllElements();
    }
    
    //**********************************************************************
    
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        CountryNameLabel = new javax.swing.JLabel();
        CountryNameTextField = new javax.swing.JTextField();
        CountryEnglishBriefLabel = new javax.swing.JLabel();
        CountryEnglishBriefTextField = new javax.swing.JTextField();
        CountryChineseBriefLabel = new javax.swing.JLabel();
        CountryChineseBriefTextField = new javax.swing.JTextField();
        CountryIdLabel = new javax.swing.JLabel();
        CountryIdTextField = new javax.swing.JTextField();
        CountryTypeLabel = new javax.swing.JLabel();
        countryTypeComboBox = new javax.swing.JComboBox<>();
        CountryBirthLabel = new javax.swing.JLabel();
        CountryBirthTextField = new javax.swing.JTextField();
        CountryInfoLabel = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        CountryInfoTextArea = new javax.swing.JTextArea();
        FlagLabel = new javax.swing.JLabel();
        addButton = new javax.swing.JButton();
        delButton = new javax.swing.JButton();
        editButton = new javax.swing.JButton();
        searchButton = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        resultList = new javax.swing.JList<>();
        CountryFlagPathLabel = new javax.swing.JLabel();
        pathTextField = new javax.swing.JTextField();
        tipLabel = new javax.swing.JLabel();
        browseButton = new javax.swing.JButton();
        ReturnButton = new javax.swing.JButton();
        clearButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Flag Manage");

        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        CountryNameLabel.setFont(new java.awt.Font("宋体", 1, 18)); // NOI18N
        CountryNameLabel.setText("国家");
        jPanel1.add(CountryNameLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(72, 21, -1, -1));
        jPanel1.add(CountryNameTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(116, 21, 180, -1));

        CountryEnglishBriefLabel.setFont(new java.awt.Font("宋体", 1, 18)); // NOI18N
        CountryEnglishBriefLabel.setText("英文简称");
        jPanel1.add(CountryEnglishBriefLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(34, 86, -1, -1));
        jPanel1.add(CountryEnglishBriefTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(116, 86, 111, -1));

        CountryChineseBriefLabel.setFont(new java.awt.Font("宋体", 1, 18)); // NOI18N
        CountryChineseBriefLabel.setText("中文简称");
        jPanel1.add(CountryChineseBriefLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(34, 52, -1, -1));
        jPanel1.add(CountryChineseBriefTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(116, 52, 111, -1));

        CountryIdLabel.setFont(new java.awt.Font("宋体", 1, 18)); // NOI18N
        CountryIdLabel.setText("国家序号");
        jPanel1.add(CountryIdLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(34, 123, -1, -1));
        jPanel1.add(CountryIdTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(116, 123, 61, -1));

        CountryTypeLabel.setFont(new java.awt.Font("宋体", 1, 18)); // NOI18N
        CountryTypeLabel.setText("发展阶段");
        jPanel1.add(CountryTypeLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(34, 155, -1, -1));

        countryTypeComboBox.setFont(new java.awt.Font("宋体", 1, 15)); // NOI18N
        countryTypeComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "发达国家", "发展中国家", "贫穷国家", "地区" }));
        countryTypeComboBox.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel1.add(countryTypeComboBox, new org.netbeans.lib.awtextra.AbsoluteConstraints(116, 154, -1, -1));

        CountryBirthLabel.setFont(new java.awt.Font("宋体", 1, 18)); // NOI18N
        CountryBirthLabel.setText("建国时间");
        jPanel1.add(CountryBirthLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(34, 187, -1, -1));
        jPanel1.add(CountryBirthTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(116, 187, 111, -1));

        CountryInfoLabel.setFont(new java.awt.Font("宋体", 1, 18)); // NOI18N
        CountryInfoLabel.setText("国家简介");
        jPanel1.add(CountryInfoLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(34, 249, -1, -1));

        CountryInfoTextArea.setColumns(20);
        CountryInfoTextArea.setRows(5);
        jScrollPane1.setViewportView(CountryInfoTextArea);

        jPanel1.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(116, 249, 233, 91));

        FlagLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imgpk/zhongguo.png"))); // NOI18N
        FlagLabel.setText("jLabel8");
        jPanel1.add(FlagLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(322, 21, 273, -1));

        addButton.setText("注册");
        addButton.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        addButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addButtonActionPerformed(evt);
            }
        });
        jPanel1.add(addButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(357, 249, 97, 30));

        delButton.setText("删除");
        delButton.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        delButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                delButtonActionPerformed(evt);
            }
        });
        jPanel1.add(delButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 249, 97, 30));

        editButton.setText("修改");
        editButton.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        editButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editButtonActionPerformed(evt);
            }
        });
        jPanel1.add(editButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(357, 310, 97, 30));

        searchButton.setText("查找");
        searchButton.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        searchButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchButtonActionPerformed(evt);
            }
        });
        jPanel1.add(searchButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 310, 97, 30));

        resultList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                resultListValueChanged(evt);
            }
        });
        jScrollPane2.setViewportView(resultList);

        jPanel1.add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(14, 369, 595, 161));

        CountryFlagPathLabel.setFont(new java.awt.Font("宋体", 1, 18)); // NOI18N
        CountryFlagPathLabel.setText("存储位置");
        jPanel1.add(CountryFlagPathLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(34, 221, -1, -1));
        jPanel1.add(pathTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(116, 218, 360, -1));

        tipLabel.setBackground(new java.awt.Color(255, 0, 0));
        tipLabel.setFont(new java.awt.Font("宋体", 1, 15)); // NOI18N
        jPanel1.add(tipLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(216, 347, 236, 18));

        browseButton.setFont(new java.awt.Font("宋体", 1, 15)); // NOI18N
        browseButton.setText("浏览");
        browseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                browseButtonActionPerformed(evt);
            }
        });
        jPanel1.add(browseButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 220, -1, 20));

        ReturnButton.setText("返回");
        ReturnButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ReturnButtonActionPerformed(evt);
            }
        });

        clearButton.setText("清空");
        clearButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 17, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(125, 125, 125)
                .addComponent(clearButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(ReturnButton)
                .addGap(119, 119, 119))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ReturnButton)
                    .addComponent(clearButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void ReturnButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ReturnButtonActionPerformed
        // TODO add your handling code here:
        
        new AdGoFrame();
        this.dispose();
        
    }//GEN-LAST:event_ReturnButtonActionPerformed

    private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
        // TODO add your handling code here:
        
        this.tempCountry = getCountryInstance();
        
        // 生成插入语句  （将当前国家对象写入数据库）
        String sql = "insert into CountryTable values('"
                + this.tempCountry.getCountryName() + "','" 
                + this.tempCountry.getCountryChineseBrief() + "','" 
                + this.tempCountry.getCountryEnglishBrief() + "','"
                + this.tempCountry.getCountryType() + "','"
                + this.tempCountry.getCountryBirth() + "','"
                + this.tempCountry.getCountryInfo() + "',"
                + this.tempCountry.getCountryId() + ",'"
                + this.tempCountry.getCountryFlagPath() 
                + "')";
      
        // 执行插入
        DBO.DBUpdate(sql);
        this.tipLabel.setText("插入完成");
        
        //当前对象传入Model
        this.defaultListModel.addElement(tempCountry);
        
        
    }//GEN-LAST:event_addButtonActionPerformed

    private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
        // TODO add your handling code here:
        this.fc.showOpenDialog(null);
        File f = fc.getCurrentDirectory();
        if(f != null){
            this.countryFlagPath = fc.getSelectedFile().getAbsolutePath();
            this.pathTextField.setText(this.countryFlagPath);
        }
    }//GEN-LAST:event_browseButtonActionPerformed

    private void delButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_delButtonActionPerformed
        // TODO add your handling code here:
        
        this.tempCountry = getCountryInstance();
        
        // 生成删除语句  （将当前国家对象从数据库删除）
        String sql = "delete from CountryTable where countryName='" + this.tempCountry.getCountryName() + "'";
        
        // 执行删除语句
        this.DBO.DBUpdate(sql);
        
        // 完成提示
        this.tipLabel.setText("删除完成");
        
        // 将当前对象从Model移除
        this.resultList.clearSelection();
        this.defaultListModel.removeElement(this.tempCountry);
    }//GEN-LAST:event_delButtonActionPerformed

    private void editButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editButtonActionPerformed
        // TODO add your handling code here:
        
        int currentIndex = this.resultList.getSelectedIndex();
        tempCountry = getCountryInstance();
        
        // 生成更新语句
        String sql = "update CountryTable set countryName='" + this.tempCountry.getCountryName() 
                + "',countryChineseBrief='" + this.tempCountry.getCountryChineseBrief() 
                + "',countryEnglishBrief='" + this.tempCountry.getCountryEnglishBrief()
                + "',countryType='" + this.tempCountry.getCountryType()
                + "',countryBirth='" + this.tempCountry.getCountryBirth()
                + "',countryInfo='" + this.tempCountry.getCountryInfo()
                + "',countryFlagPath='" + this.tempCountry.getCountryFlagPath()
                + "' where countryId=" + this.tempCountry.getCountryId();
        
        // 执行更新语句
        this.DBO.DBUpdate(sql);
        
        //更新Model
        this.defaultListModel.setElementAt(tempCountry, this.resultList.getSelectedIndex());
        
        // 完成提示
        this.tipLabel.setText("修改完成");
        
    }//GEN-LAST:event_editButtonActionPerformed

    private void searchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchButtonActionPerformed
        
       
        String sql = "select * from CountryTable";

        this.defaultListModel.removeAllElements();
        this.DBO.DBQuary(sql);
        
        if(this.CountryChineseBriefTextField.getText().equals("")){
            try{
                // 扫描数据库
                while(this.DBO.getRs().next()){

                    // 构造对象
                    tempCountry = new Country();
                    tempCountry.setCountryName(this.DBO.getRs().getString("countryName"));
                    tempCountry.setCountryChineseBrief(this.DBO.getRs().getString("countryChineseBrief"));
                    tempCountry.setCountryEnglishBrief(this.DBO.getRs().getString("countryEnglishBrief"));
                    tempCountry.setCountryId(this.DBO.getRs().getString("countryId"));
                    tempCountry.setCountryBirth(this.DBO.getRs().getString("countryBirth"));
                    tempCountry.setCountryType(this.DBO.getRs().getString("countryType"));
                    tempCountry.setCountryFlagPath(this.DBO.getRs().getString("CountryFlagPath"));
                    tempCountry.setCountryInfo(this.DBO.getRs().getString("countryInfo"));


                    //传入Model
                    this.defaultListModel.addElement(tempCountry);
                }

            }catch(SQLException e){
                e.printStackTrace();
            }
        }
        else{
            try{
                
                while(this.DBO.getRs().next()){
                    if(this.CountryChineseBriefTextField.getText().equals(this.DBO.getRs().getString("countryChineseBrief"))){
                        // 构造对象
                        tempCountry = new Country();
                        tempCountry.setCountryName(this.DBO.getRs().getString("countryName"));
                        tempCountry.setCountryChineseBrief(this.DBO.getRs().getString("countryChineseBrief"));
                        tempCountry.setCountryEnglishBrief(this.DBO.getRs().getString("countryEnglishBrief"));
                        tempCountry.setCountryId(this.DBO.getRs().getString("countryId"));
                        tempCountry.setCountryBirth(this.DBO.getRs().getString("countryBirth"));
                        tempCountry.setCountryType(this.DBO.getRs().getString("countryType"));
                        tempCountry.setCountryFlagPath(this.DBO.getRs().getString("CountryFlagPath"));
                        tempCountry.setCountryInfo(this.DBO.getRs().getString("countryInfo"));


                        //传入Model
                        this.defaultListModel.addElement(tempCountry);
                        //显示
                        showInstance();
                        //更新图片
                        this.flagPath = tempCountry.getCountryFlagPath();
                        this.flagImage = new ImageIcon(flagPath);
                        this.FlagLabel.setIcon(flagImage);
                    }
                }
                
            }catch(SQLException e){
                e.printStackTrace();
            }
        }
            
            
            /*
            try{
                // 扫描数据库
                while(this.DBO.getRs().next()){
                    
                    // 构造对象
                    tempCountry = new Country();
                    tempCountry.setCountryName(this.DBO.getRs().getString("countryName"));
                    tempCountry.setCountryChineseBrief(this.DBO.getRs().getString("countryChineseBrief"));
                    tempCountry.setCountryEnglishBrief("countryEnglishBrief");
                    tempCountry.setCountryId(this.DBO.getRs().getString("countryId"));
                    tempCountry.setCountryBirth(this.DBO.getRs().getString("countryBirth"));
                    tempCountry.setCountryType(this.DBO.getRs().getString("countryType"));
                    tempCountry.setCountryFlagPath(this.DBO.getRs().getString("CountryFlagPath"));
                    tempCountry.setCountryInfo(this.DBO.getRs().getString("countryInfo"));
                    
                    
                    //传入Model
                    this.defaultListModel.addElement(tempCountry);
                }
                
            }catch(SQLException e){
                e.printStackTrace();
            }
            */  
    }//GEN-LAST:event_searchButtonActionPerformed

    private void resultListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_resultListValueChanged
        // TODO add your handling code here:
        int currentIndex;
        if((!this.defaultListModel.isEmpty()) && (!this.resultList.isSelectionEmpty())){
            currentIndex = this.resultList.getSelectedIndex();
            this.tempCountry = (Country)this.defaultListModel.getElementAt(currentIndex);
            showInstance();
            this.flagPath = tempCountry.getCountryFlagPath();
            this.flagImage = new ImageIcon(flagPath);
            this.FlagLabel.setIcon(flagImage);
        }
        else{
            
        }
        
    }//GEN-LAST:event_resultListValueChanged

    private void clearButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearButtonActionPerformed
        // TODO add your handling code here:
        clearAll();
    }//GEN-LAST:event_clearButtonActionPerformed

    
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FlagFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FlagFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FlagFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FlagFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FlagFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel CountryBirthLabel;
    private javax.swing.JTextField CountryBirthTextField;
    private javax.swing.JLabel CountryChineseBriefLabel;
    private javax.swing.JTextField CountryChineseBriefTextField;
    private javax.swing.JLabel CountryEnglishBriefLabel;
    private javax.swing.JTextField CountryEnglishBriefTextField;
    private javax.swing.JLabel CountryFlagPathLabel;
    private javax.swing.JLabel CountryIdLabel;
    private javax.swing.JTextField CountryIdTextField;
    private javax.swing.JLabel CountryInfoLabel;
    private javax.swing.JTextArea CountryInfoTextArea;
    private javax.swing.JLabel CountryNameLabel;
    private javax.swing.JTextField CountryNameTextField;
    private javax.swing.JLabel CountryTypeLabel;
    private javax.swing.JLabel FlagLabel;
    private javax.swing.JButton ReturnButton;
    private javax.swing.JButton addButton;
    private javax.swing.JButton browseButton;
    private javax.swing.JButton clearButton;
    private javax.swing.JComboBox<String> countryTypeComboBox;
    private javax.swing.JButton delButton;
    private javax.swing.JButton editButton;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField pathTextField;
    private javax.swing.JList<String> resultList;
    private javax.swing.JButton searchButton;
    private javax.swing.JLabel tipLabel;
    // End of variables declaration//GEN-END:variables
}
